﻿<!--#include file="h.asp"--><!--#include file="libs/upload.asp"--><%
'
'	七色虎建站系统
'	保存文件帖
'	2012.6.2

Sub main
	Dim userid,body_,classid,text,title,id,price,length_
	userid=user_array(0)
	checkLogin()'验证登录
	hu.title = "发文件帖"
	' body_ = checkMsg()'信息
	If hu.Style = 1 Then rupt "错误","当前浏览器不支持文件上传!"
	'论坛文件上传配置
	If bbsFileUp="" Then bbsFileUp="1"'论坛默认允许文件上传
	If bbsFileUp="0" Then rupt "错误","管理员已禁止文件上传!"
	If bbsFileType="" Then bbsFileType="rar|zip|gif|jpg|png|mp3|wma"'允许文件类型
	If Not ifNum(bbsFileSize) Then bbsFileSize="500"'论坛默认允许文件上传大小(k)
	Server.ScriptTimeOut=999999
	body_ = body_ & "[div=nav]-"&hu.url("?aid=index","首页")&"-发文件帖[/div]"
	allowSize = bbsFileSize * 1024
	allowType = bbsFileType

	Dim timeInterval'防止刷帖,20秒发表一条;发帖间隔超过60s,加金币积分经验
	timeInterval=0
	Set rs=hu.conn("select top 1 savetime from 74hu_topic where userid="&userid&" order by id desc")
	If Not rs.eof Then
		timeInterval = DateDiff("s", rs("savetime"), time_now)
		If timeInterval <20 Then rupt "错误", "为提高发帖质量,两次发帖间隔必须大于20秒!"
	End If

	Dim ranNum,fileName,upload,fileSize,result,items',formName
	Dim fso,formPath,formPath1

	If not ifObjInstalled("Scripting.FileSystemObject") Then rupt "错误", "服务器不支持文件上传功能！"

	Set fso=Server.CreateObject("Scripting.FileSystemObject")
	formPath = "upload/"&year(time_now)&"/"&Right("0"&month(time_now),2)&Right("0"&day(time_now),2)&"/"
	filePath= Server.mappath(formPath)

	call fCreateFolderByPath(fso, filePath)
	Set fso=Nothing

	filePath=filePath&"/"

	randomize
	ranNum=Right("0"&hour(time_now),2)&Right("0"&minute(time_now),2)&Right("0"&second(time_now),2)&int(90000*rnd)+10000

	Set upload=New upload_5xsoft '建立上传对象

	classid = upload.form("id")
	text = upload.form("text")
	title = upload.form("title")
	price = upload.form("price")

	If Not ifNum(classid) Then rupt "错误","参数id不能为空!"
	If title="" Then rupt "错误","帖子标题不能为空!"
	If text="" Then rupt "错误","帖子内容不能为空!"
	If Not ifNum(price) Then rupt "错误","帖子需要"&bbsMoney&"不能为空!"
	length_ = len(text)
	If length_<numTopicMin*1 Then rupt "错误", "内容字数必须大于"&numTopicMin&"！"
	If length_>numTopicMax*1 Then rupt "错误", "内容字数必须小于"&numTopicMax&"！"

	Set rs = hu.conn("select top 1 id from 74hu_topic where title='"&title&"' and content='"&text&"'")
	If Not rs.eof Then rupt "错误","帖子已存在！请不要重复发表"

	' for Each formName In upload.objFile '列出所有上传了的文件
	' Set file=upload.file(formName) '生成一个文件对象
	If upload.objFile.count>0 Then
		items=upload.objFile.items
		Set file=items(0) '生成文件对象
		fileSize = file.filesize
		If fileSize=0 Then
			rupt "错误","请选择你要上传的文件！"
		End If
		If fileSize>allowSize Then
			rupt "错误","文件大小超过了限制"&forFileSize(allowSize)&"！"
		End If

		fileExt=file.filename
		fileExt=LCase(Right(fileExt,Len(fileExt)-InStrRev(fileExt,".")))

		If Instr("|"&allowType&"|", "|"&fileExt&"|")=0 Then
			rupt "错误","文件格式不正确！"
		End If

		filename=filePath&ranNum&"."&fileExt'生成文件绝对地址
		formPath1=formPath&ranNum&"."&fileExt'生成文件相对地址

		If fileSize>0 Then '如果 fileSize > 0 说明有文件数据
			result = file.SaveAs(filename)'保存文件
			If result=False Then
				hu.conn("insert into 74hu_download ([userid],[url],[filesize],[filetype],[buy]) values ("&userid&",'"&formPath1&"',"&fileSize&",'"&fileExt&"',"&price&")")
				id=hu.conn("select top 1 id from 74hu_download where userid="&userid&" order by id desc")(0)
				' body_ = body_ & "文件上传成功！文件ID为"&id
			Else
				' body_ = body_ & "文件上传失败！"
				rupt "错误","文件上传失败！"
			End If
		End If
		Set file=Nothing
	End If
	' Next
	Set upload=Nothing
	If timeInterval >60 Then Call setUserAmount(userid, amtPost)'加金币积分经验
	sql = "insert into 74hu_topic (title,content,userid,classid,savetime,livetime,type,subtype)"&_
		"values('"&title&"','"&text&"',"&userid&","&classid&",'"&time_now&"','"&time_now&"',2,"&id&")"
	hu.conn(sql)
	hu.conn("update 74hu_user set topic=topic+1 where id="&userid)
	hu.autoRedirect = "bbs_topic.asp?id="&classid&"&amp;"&sid_str
	body_ = body_ & "发表成功！"&hu.url("bbs_topic.asp?id="&classid,"返回论坛")
	hu.body = comUbb(body_)
End Sub

%>